

package com.yy.permissions_general.common.config;


import com.yy.permissions_general.common.config.convert.CustomLongConverter;
import com.yy.permissions_general.common.constant.SystemConstant;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @Author: YY
 * @Date: 2021/3/14
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
//
//    @Autowired
//    private LoginInterceptor loginInterceptor;
//
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
//    }
    /**
     * @Description: 配置拦截器
     * @Author: YY
     * @Date: 2021/3/15
     */
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(loginInterceptor).addPathPatterns("/**")
//                .excludePathPatterns("/login", "/view/login", "/view/error/404", "/view/error/403", "/view/error/500", "/loginOut", "/admin/**");
//    }

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
        // 自定义Long类型转换
        builder.serializerByType(Long.class, new CustomLongConverter());
        builder.serializerByType(Long.TYPE, new CustomLongConverter());
        // 时间类型格式转换,默认为long
        builder.indentOutput(true).dateFormat(new SimpleDateFormat(SystemConstant.TIME_FORMAT));
        converters.add(0, new MappingJackson2HttpMessageConverter(builder.build()));
    }
}
